package com.example.myapplication;

import android.app.ActionBar;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.myapplication.utils.Utils;

public class ViewUsageActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_view_usage);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        // 通过代码设置视图的宽度和高度的步骤。注意，必须在activity的xml中必须设置layout_width和layout_height为wrap_content
        TextView view1 = findViewById(R.id.view2);
        ViewGroup.LayoutParams layoutParams = view1.getLayoutParams();
        layoutParams.width = Utils.dpToPx(this, 300);
        view1.setLayoutParams(layoutParams);

        // 通过代码设置layout_margin和padding
        TextView text21 = findViewById(R.id.text21);
//        ViewGroup.LayoutParams = text21.getLayoutParams();
    }
}